<html>
<head><meta charset="utf-8"><title>Change behavior of `unsafe` fns in new edition? · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Change.20behavior.20of.20.60unsafe.60.20fns.20in.20new.20edition.3F.html">Change behavior of `unsafe` fns in new edition?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="185429654"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Change%20behavior%20of%20%60unsafe%60%20fns%20in%20new%20edition%3F/near/185429654" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Kalbertodt <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Change.20behavior.20of.20.60unsafe.60.20fns.20in.20new.20edition.3F.html#185429654">(Jan 12 2020 at 11:04)</a>:</h4>
<p>Many people are not happy with the fact that <code>unsafe fn</code>s can do unsafe things inside the function body. Many would prefer if explicit <code>unsafe</code> blocks were required, like in normal functions. But let's not talk about <em>if</em> we want that. My question is: can this behavior be changed in a new edition? <br>
Seems like a surface level change to me. It does not change APIs in any way and is crate local. Should be possible, right?</p>



<a name="185433358"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Change%20behavior%20of%20%60unsafe%60%20fns%20in%20new%20edition%3F/near/185433358" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kennytm <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Change.20behavior.20of.20.60unsafe.60.20fns.20in.20new.20edition.3F.html#185433358">(Jan 12 2020 at 12:53)</a>:</h4>
<p><a href="https://github.com/rust-lang/rfcs/pull/2585" target="_blank" title="https://github.com/rust-lang/rfcs/pull/2585">https://github.com/rust-lang/rfcs/pull/2585</a></p>



<a name="185434551"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Change%20behavior%20of%20%60unsafe%60%20fns%20in%20new%20edition%3F/near/185434551" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Kalbertodt <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Change.20behavior.20of.20.60unsafe.60.20fns.20in.20new.20edition.3F.html#185434551">(Jan 12 2020 at 13:30)</a>:</h4>
<p>Thanks! That's great</p>



<a name="185447581"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Change%20behavior%20of%20%60unsafe%60%20fns%20in%20new%20edition%3F/near/185447581" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Change.20behavior.20of.20.60unsafe.60.20fns.20in.20new.20edition.3F.html#185447581">(Jan 12 2020 at 19:51)</a>:</h4>
<p><span class="user-mention" data-user-id="118772">@Lukas Kalbertodt</span> yes, it can be changed in a new edition</p>



<a name="185645016"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Change%20behavior%20of%20%60unsafe%60%20fns%20in%20new%20edition%3F/near/185645016" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Change.20behavior.20of.20.60unsafe.60.20fns.20in.20new.20edition.3F.html#185645016">(Jan 14 2020 at 21:58)</a>:</h4>
<p><span class="user-mention" data-user-id="118772">@Lukas Kalbertodt</span> I'd be happy for any support in reviving that RFC and pushing it over the finish line -- assuming we can get the conesus for that :)</p>



<a name="185645737"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Change%20behavior%20of%20%60unsafe%60%20fns%20in%20new%20edition%3F/near/185645737" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Kalbertodt <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Change.20behavior.20of.20.60unsafe.60.20fns.20in.20new.20edition.3F.html#185645737">(Jan 14 2020 at 22:05)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> That would be great. I will take a look soon, but I'm currently having lots of other stuff in my queue. Trying to get used to T-libs life :P</p>



<a name="185650427"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Change%20behavior%20of%20%60unsafe%60%20fns%20in%20new%20edition%3F/near/185650427" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Change.20behavior.20of.20.60unsafe.60.20fns.20in.20new.20edition.3F.html#185650427">(Jan 14 2020 at 22:54)</a>:</h4>
<p>I still think that it would be a very bad idea, very detrimental to unsafe code authors.</p>



<a name="185676150"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Change%20behavior%20of%20%60unsafe%60%20fns%20in%20new%20edition%3F/near/185676150" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Change.20behavior.20of.20.60unsafe.60.20fns.20in.20new.20edition.3F.html#185676150">(Jan 15 2020 at 07:58)</a>:</h4>
<p>I would be fine with accepting the RFC if we also allow <code>fn foo() -&gt; R = expr;</code></p>



<a name="185676933"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Change%20behavior%20of%20%60unsafe%60%20fns%20in%20new%20edition%3F/near/185676933" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Change.20behavior.20of.20.60unsafe.60.20fns.20in.20new.20edition.3F.html#185676933">(Jan 15 2020 at 08:13)</a>:</h4>
<p><span aria-label="upside down" class="emoji emoji-1f643" role="img" title="upside down">:upside_down:</span> <code>fn foo: fn() -&gt; R = expr;</code> for symmetry with other globals</p>



<a name="185676986"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Change%20behavior%20of%20%60unsafe%60%20fns%20in%20new%20edition%3F/near/185676986" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Change.20behavior.20of.20.60unsafe.60.20fns.20in.20new.20edition.3F.html#185676986">(Jan 15 2020 at 08:14)</a>:</h4>
<p>(I know arguments and such make this impossible, I am not actually suggesting this)</p>



<a name="185679635"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Change%20behavior%20of%20%60unsafe%60%20fns%20in%20new%20edition%3F/near/185679635" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Change.20behavior.20of.20.60unsafe.60.20fns.20in.20new.20edition.3F.html#185679635">(Jan 15 2020 at 09:02)</a>:</h4>
<blockquote>
<p>I still think that it would be a very bad idea, very detrimental to unsafe code authors.</p>
</blockquote>
<p>I'm not opposed to having some syntactic sugar that makes it easy to define an unsafe fn with unsafe body when you want to. But I think the current status is indeed more detrimental to unsafe code authors -- I have met plenty of people that fundamentally misunderstood the "proof obligation" nature of unsafe blocks because of the way <code>unsafe fn</code> makes everything inconsistent.</p>



<a name="185679699"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Change%20behavior%20of%20%60unsafe%60%20fns%20in%20new%20edition%3F/near/185679699" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Change.20behavior.20of.20.60unsafe.60.20fns.20in.20new.20edition.3F.html#185679699">(Jan 15 2020 at 09:03)</a>:</h4>
<p>(the <code>= expr;</code> stuff is intended as the sugar, e.g. <code>unsafe fn foo() = unsafe { ... };</code>)</p>



<a name="185680364"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Change%20behavior%20of%20%60unsafe%60%20fns%20in%20new%20edition%3F/near/185680364" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Change.20behavior.20of.20.60unsafe.60.20fns.20in.20new.20edition.3F.html#185680364">(Jan 15 2020 at 09:14)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> the fact that rust does not let you even attempt to properly describe the proof obligations in a checked way is its own whole other problem</p>



<a name="185680465"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Change%20behavior%20of%20%60unsafe%60%20fns%20in%20new%20edition%3F/near/185680465" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Change.20behavior.20of.20.60unsafe.60.20fns.20in.20new.20edition.3F.html#185680465">(Jan 15 2020 at 09:15)</a>:</h4>
<p>I think there's absolutely an educational gap when it comes to <code>unsafe</code> code</p>



<a name="185680685"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Change%20behavior%20of%20%60unsafe%60%20fns%20in%20new%20edition%3F/near/185680685" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Change.20behavior.20of.20.60unsafe.60.20fns.20in.20new.20edition.3F.html#185680685">(Jan 15 2020 at 09:18)</a>:</h4>
<p>I don't think that making people fill their functions with more <code>unsafe { ... }</code> around expressions will fix that gap.</p>



<a name="185714306"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Change%20behavior%20of%20%60unsafe%60%20fns%20in%20new%20edition%3F/near/185714306" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Change.20behavior.20of.20.60unsafe.60.20fns.20in.20new.20edition.3F.html#185714306">(Jan 15 2020 at 16:24)</a>:</h4>
<blockquote>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> the fact that rust does not let you even attempt to properly describe the proof obligations in a checked way is its own whole other problem</p>
</blockquote>
<p>indeed it is, which is why I dont understand why you are even mentioning it</p>



<a name="185714381"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Change%20behavior%20of%20%60unsafe%60%20fns%20in%20new%20edition%3F/near/185714381" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Change.20behavior.20of.20.60unsafe.60.20fns.20in.20new.20edition.3F.html#185714381">(Jan 15 2020 at 16:24)</a>:</h4>
<p>when I am talking about people misunderstanding <code>unsafe</code>, that has nothing to do with making rustc understand the involved proof obligations any better</p>



<a name="185719629"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Change%20behavior%20of%20%60unsafe%60%20fns%20in%20new%20edition%3F/near/185719629" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Change.20behavior.20of.20.60unsafe.60.20fns.20in.20new.20edition.3F.html#185719629">(Jan 15 2020 at 17:10)</a>:</h4>
<blockquote>
<p>I still think that it would be a very bad idea, very detrimental to unsafe code authors.</p>
</blockquote>
<p>ISTM it would allow unsafe code authors to make a cleaner separation between <code>unsafe</code> as in implementation details and <code>unsafe</code> as in a contract between an API and its users. That seems like a reasonable thing to have (at the cost of some verbosity), so I wouldn't call it _detrimental_.</p>



<a name="185789280"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Change%20behavior%20of%20%60unsafe%60%20fns%20in%20new%20edition%3F/near/185789280" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Change.20behavior.20of.20.60unsafe.60.20fns.20in.20new.20edition.3F.html#185789280">(Jan 16 2020 at 06:25)</a>:</h4>
<p>(deleted)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>